/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bda.mediatheque.service;

import com.bda.mediatheque.entities.Utilisateur;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;

/**
 *
 * @author samsung
 */
public class Test {
 
       public static void main(String args[]) {
        Utilisateur user = new Utilisateur();
        user.setIdUtilisateur(Integer.MIN_VALUE);
        user.setNom("Ouertani");
        user.setPrenom("Ahmed");
       

        Test demo = new Test();
        demo.persist(user);
    }

    public void persist(Object object) {
        EntityManagerFactory emf = javax.persistence.Persistence.createEntityManagerFactory("MediaPU");
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        try {
            em.persist(object);
            em.getTransaction().commit();
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
    }
    
    public List getUtilisateurList() {
        
        EntityManagerFactory emf = javax.persistence.Persistence.createEntityManagerFactory("MediaPU");
        EntityManager em = emf.createEntityManager();
        
       
        return  em.createQuery("select p from Utilisateur p").getResultList();
    }
}
